package com.contexttree.filereader;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import com.contexttree.gui.SwingView;
import com.contexttree.gui.TextualView;
import com.contexttree.utils.Printer;

/**
 * The main class of ContextTree analysis application, this class launch the textual mode or graphic mode.
 * Politecnico di Milano 2012
 * @author Paolo Barbaglia
 * @author Filippo Ferrari
 *
 */
public class Main {

	/**
	 * Main class
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		//Variable for read input stream
        InputStreamReader reader = new InputStreamReader (System.in);
        BufferedReader myInput = new BufferedReader (reader);
		String inputApplicationMode = "";
		
        inputApplicationMode = chooseApplicationMode(myInput,inputApplicationMode);
        int k = Integer.parseInt(inputApplicationMode);
        switch (k) {
        case 1:
			launchTextualMode();
        	break;
        case 2:
			launchGraphicalMode();
        	break;
        default:
        	Printer.print("Nothig to do");
        	break;
        } 
	}
	
	/**
	 * This method read from keyboard the user selection.
	 * @param myInput
	 * @param inputApplicationMode
	 * @return inputApplicationMode
	 */
	public static String chooseApplicationMode(BufferedReader myInput, String inputApplicationMode){
		Printer.print("Choose the application mode: (1) Textual or (2) Graphical");
		try {
			inputApplicationMode = myInput.readLine();
		} catch (IOException e) {
			Printer.print(e);
		}
		return inputApplicationMode;
	}
	
	/**
	 * Launch a SwingView.run method that launch a graphical mode
	 */
	public static void launchGraphicalMode() {
		SwingView.run();
	}
	
	/**
	 * Launch TextualView.start method that launch a textual mode
	 * @throws IOException
	 */
	public static void launchTextualMode() throws IOException {
		TextualView text = new TextualView();
		text.start(0);
	}
}